package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.entity.CommonResult;
import com.atguigu.springcloud.entity.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @Author: fxy
 * @Date: 2021/10/12/10:09
 * @Description:
 */
@RestController
@Slf4j
@RequestMapping("/Order")
public class OrderController {
    @Resource
    private RestTemplate restTemplate;

    public static final String PAYMENT_URL = "http://CLOUD-PAYMENT-SERVICE";


    @GetMapping("/createPayment")
    public CommonResult<Payment> create(Payment payment){
        return restTemplate.postForObject(PAYMENT_URL +"/Payment/create",payment,CommonResult.class);
    }

    @GetMapping("/getPayment/{id}")
    public CommonResult<Payment> create(@PathVariable Long id){
        return restTemplate.getForObject(PAYMENT_URL +"/Payment/get/"+id,CommonResult.class);
    }

    @GetMapping("/zk")
    public String paymentinfo(){
        return restTemplate.getForObject("http://cloud-payment-service"+"/Payment/zk",String.class);
    }
}
